package com.zhentao.controller;

import com.github.pagehelper.PageInfo;
import com.zhentao.model.dto.product.ProductDto;
import com.zhentao.model.entity.product.Product;
import com.zhentao.model.vo.common.Result;
import com.zhentao.model.vo.common.ResultCodeEnum;
import com.zhentao.service.ProductService;
import com.zhentao.service.ProductUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/admin/product/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private ProductUnitService productUnitService;

    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Product>> findByPage(@PathVariable int page, @PathVariable int limit, ProductDto productDto) {
        PageInfo<Product> byPage = productService.findByPage(page, limit, productDto);
        return Result.build(byPage,  ResultCodeEnum.SUCCESS);
    }


//    @GetMapping("/productSpecList")
//    public Result productSpecList(){
//        return productSpecService.ProductSpecFindAll();
//    }

    @GetMapping("/productUnitList")
    public Result productUnitList(){
        return productUnitService.productUnit();
    }

    @PostMapping("/portductAdd")
    public Result productAdd(@RequestBody Product product){
        return productService.productSave(product);
    }

    @GetMapping("/productFindOne/{id}")
    public Result productFindOne(@PathVariable Long id){
        return productService.productFindOne(id);
    }

    @PutMapping("/productUpdate")
    public Result productUpdate(@RequestBody Product product){
        return productService.productUpdate(product);
    }

    @DeleteMapping("/productDelete/{id}")
    public Result productDelete(@PathVariable Long id){
        return productService.productDelete(id);
    }

    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable Long id, @PathVariable Integer auditStatus) {
        productService.updateAuditStatus(id, auditStatus);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        productService.updateStatus(id, status);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //    前端添加图片的路径添加到minio
    @PostMapping("file")
    public String file(MultipartFile file){
        String  file1 = productService.file(file);
        return file1;
    }



}
